package composite

import (
	"fmt"
	"strings"
)

type ICompany interface {
	Add(ic ICompany)
	Remove(ic ICompany)
	Display(depth int)
	LineOfDuty()
}

type ConcreteCompany struct {
	Name string
	List map[ICompany]ICompany
}

func NewConcreteCompany(name string) *ConcreteCompany {
	list := make(map[ICompany]ICompany)
	return &ConcreteCompany{
		Name: name,
		List: list,
	}
}

func (cc *ConcreteCompany) Add(ic ICompany) {
	cc.List[ic] = ic
}

func (cc *ConcreteCompany) Remove(ic ICompany) {
	delete(cc.List, ic)
}

func (cc *ConcreteCompany) Display(depth int) {
	fmt.Println(strings.Repeat("-", depth), " ", cc.Name)
	for _, ccc := range cc.List {
		ccc.Display(depth + 2)
	}
}

func (cc *ConcreteCompany) LineOfDuty() {
	for _, ccc := range cc.List {
		ccc.LineOfDuty()
	}
}

type HRDepartment struct {
	Name string
}

func NewHRDepartment(name string) *HRDepartment {
	return &HRDepartment{
		Name: name,
	}
}

func (hrd *HRDepartment) Add(ic ICompany) {
}

func (hrd *HRDepartment) Remove(ic ICompany) {
}

func (hrd *HRDepartment) Display(depth int) {
	fmt.Println(strings.Repeat("-", depth), " ", hrd.Name)
}

func (hrd *HRDepartment) LineOfDuty() {
	fmt.Println(hrd.Name, "员工招聘培训管理")
}

type FinanceDepartment struct {
	Name string
}

func NewFinanceDepartment(name string) *FinanceDepartment {
	return &FinanceDepartment{
		Name: name,
	}
}

func (fd *FinanceDepartment) Add(ic ICompany) {
}

func (fd *FinanceDepartment) Remove(ic ICompany) {
}

func (fd *FinanceDepartment) Display(depth int) {
	fmt.Println(strings.Repeat("-", depth), " ", fd.Name)
}

func (fd *FinanceDepartment) LineOfDuty() {
	fmt.Println(fd.Name, "公司财务收支管理")
}
